home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / kerberos / pc / krb_libk.lha / Lib / KRB / NETREAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-01  |  1.2 KB  |  56 lines

  1. /*
  2.  * $Source: /mit/kerberos/src/lib/krb/RCS/netread.c,v $
  3.  * $Author: jtkohl $
  4.  *
  5.  * Copyright 1987, 1988 by the Massachusetts Institute of Technology.
  6.  *
  7.  * For copying and distribution information, please see the file
  8.  * <mit-copyright.h>.
  9.  */
  10.  
  11. #ifndef    lint
  12. static char rcsid_netread_c[] =
  13. "$Header: netread.c,v 4.1 88/11/15 16:47:21 jtkohl Exp $";
  14. #endif    lint
  15.  
  16. #include <mit_copy.h>
  17. #include <conf.h>
  18. #include <sys/socket.h>
  19.  
  20. /*
  21.  * krb_net_read() reads from the file descriptor "fd" to the buffer
  22.  * "buf", until either 1) "len" bytes have been read or 2) cannot
  23.  * read anymore from "fd".  It returns the number of bytes read
  24.  * or a read() error.  (The calling interface is identical to
  25.  * read(2).)
  26.  *
  27.  * XXX must not use non-blocking I/O
  28.  */
  29.  
  30. int
  31. krb_net_read(fd, buf, len)
  32. int fd;
  33. register char *buf;
  34. register int len;
  35. {
  36.     int cc, len2 = 0;
  37.  
  38.     do {
  39. #ifdef IBMPC
  40.     cc=soread(fd,buf,len);
  41. #else
  42.     cc = read(fd, buf, len);
  43. #endif
  44.     if (cc < 0)
  45.         return(cc);         /* errno is already set */
  46.     else if (cc == 0) {
  47.         return(len2);
  48.     } else {
  49.         buf += cc;
  50.         len2 += cc;
  51.         len -= cc;
  52.     }
  53.     } while (len > 0);
  54.     return(len2);
  55. }
  56.